/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbeans;

import Entities.Modelerdp;
import Entities.Utilisateur;
import SessionBeans.RdPManager;
import SessionBeans.Users;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Dorra
 */
@Named(value = "usersMBean")
@SessionScoped
public class UsersMBean implements Serializable {
    @EJB
    private Users users;
    

            
     private String login;
     private String password;
     private String type;

    /** Creates a new instance of UsersMBean */
    public UsersMBean() {
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
    
      public UsersMBean(String login, String password) {
        
      }
     
      public String auth()
      {
          Utilisateur u = new Utilisateur();
          u.setLogin(login);
          u.setMotPasse(Integer.parseInt(password));
          List<Utilisateur> h = users.authentification(login);
          if(h.isEmpty()){
               return "failed";   
          }
          else
          {
              Utilisateur u1 = h.get(0);
              if(u1.getMotPasse()==Integer.parseInt(password)&& u1.getType()==1)
              {
                   return "choix";
              }
            
          }
          return "failed";
          
      }
      public String access()
      {
          return "ModeleRDP";
      }
      public String applet()
      {
          return "applet";
      }
      public String choix()
      {
          return "choix";
      }
     
    
 
}
    

 

